package com.dxy.hms.controller;

import com.alibaba.fastjson.JSONObject;
import com.dxy.hms.base.Resp;
import com.dxy.hms.socketio.ISessionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/hms/socketIoTest")
public class SocketIoTestController {

    @Autowired
    private ISessionService sessionService;


    @PostMapping("/testSendMessageByUserId/{userId}")
    public Resp testSendMessageByUserId(@PathVariable("userId")String userId,
                                        @RequestBody JSONObject message){
        // 前端socket.io-client中要用 socket.on('test_event', msg => {})监听此事件
        sessionService.sendMessageByUserId(userId, "test_event", message);
        return Resp.bizSuccess();
    }
}
